package com.groupnections.client.groups;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.groupnections.client.user.ListUsers;
import com.groupnections.shared.entities.Groups;

/**
 * 
 * @UserManual
 */
public class GroupsList extends VerticalPanel {

	public GroupsList(String[] groups) {

		if (groups != null) {

			for (String group : groups) {

				this.add(groupLink(group));

			}
		}
		this.add(groupLink(Groups.GROUP_NONE));
	}

	private Anchor groupLink(final String group) {

		Anchor groupName = new Anchor(group);
		groupName.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {

				new ListUsers(group);

			}
		});

		return groupName;
	}

}
